package com.gopay.webtest.util;

import java.lang.reflect.Field;

import com.gopay.webtest.vo.CommonResp;
import com.gopay.webtest.vo.PayInfo;

public class PropertyUtil {

	public static void copyProperty(Object srcObj , Object tarObj ){
		//field.setAccessible(true);
		
		Field[] srcFields =  srcObj.getClass().getDeclaredFields();
		Field[] tarFields = tarObj.getClass().getDeclaredFields();
		
		for(Field tarField : tarFields){
			
			tarField.setAccessible(true);
			
			for(Field srcField :srcFields ){
				
				srcField.setAccessible(true);
				
				if(srcField.getName().equals(tarField.getName())){
					
					try {
						tarField.set(tarObj, srcField.get(srcObj));
					} catch (IllegalArgumentException e) {
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					break;
				}
				
			}
		}
		
		
	}
	
	
	public static void main(String[] args) {
		
		PayInfo p = new PayInfo();
		
		p.setAuthID("12345678");
		p.setBackgroundMerUrl("http://locahost:8080/tiger");
		p.setBuyerName("tiger");
		
		CommonResp r = new CommonResp();
		
		copyProperty(p,r);
		
		System.out.println(r.getBackgroundMerUrl());
		System.out.println(r.getBuyerName());
	}
}
